import request from '../utils/request';

export function getOperLog(log,pageIndex,pageSize){
    return request({
        url: '/log/getOperLog',
        method: 'post',
        params: {
            pageIndex,
            pageSize
        },
        data: log

    });
}

export function register(username, password,email){
    return request({
        url: '/user/register',
        method: 'post',
        data: {username: username,
            password:password,
        email:email}
    });
}
export function sendEmail(email){
    return request({
        url: '/user/sendEmail',
        method: 'get',
        params: {
            email:email
        }
    });
}
export function getInfo(){
    return request({
        url: '/sys/getInfo',
        method: 'get'
    });
}
export default{
    getFileList(file,pageIndex,pageSize){
        return request({
            url: '/file/getFile',
            method: 'get',
            params: {
                file: file,
                pageIndex,
                pageSize
            }
        });
    },
    downFile(url){
        return request({
            url: url,
            method: 'get',
        });
    },
    deleteLog(idList){
        return request({
            url: '/log/deleteLog',
            method: 'post',
            params: {
                idList: idList,
                tableName: 'oper_log',
            }
        });
    },
    getExceptionLog(log,pageIndex,pageSize){
        return request({
            url: '/log/getExceptionLog',
            method: 'post',
            params: {
                pageIndex,
                pageSize
            },
            data: log
        });
    },
    pay(order){
        return request({
            url: '/order/pay',
            method: 'post',
            data: order
        });
    },



    // 权限管理
    getPermission(permission,pageIndex,pageSize){
        return request({
            url: '/permission/getPermission',
            method: 'post',
            params: {
                pageIndex,
                pageSize
            },
            data: permission
        });
    },
    getRole(role,pageIndex,pageSize){
        return request({
            url: '/role/getRole',
            method: 'post',
            params: {
                pageIndex,
                pageSize
            },
            data: role
        });
    },
    getUser(user,pageIndex,pageSize){
        return request({
            url: '/userManager/getUser',
            method: 'post',
            params: {
                pageIndex,
                pageSize
            },
            data: user
        });
    },

    getRoleByUser(userId) {
        return request({
            url: '/role/getRoleByUserId',
            method: 'get',
            params: {
                userId
            }
        });
    },
    getPermissionByRole(roleId) {
        return request({
            url: '/permission/getPermissionByRoleId',
            method: 'get',
            params: {
                roleId
            }
        });
    },
    addRoleToUser(userId,roleId) {
        return request({
            url: '/role/addRoleToUser',
            method: 'get',
            params: {
                userId,
                roleId
            }
        });
    },
    deleteRoleToUser(userId,roleId) {
        return request({
            url: '/role/deleteRoleToUser',
            method: 'get',
            params: {
                userId,
                roleId
            }
        });
    },
    deletePermissionToRole(roleId,permissionId) {
        return request({
            url: '/permission/deletePermissionToRole',
            method: 'get',
            params: {
                permissionId,
                roleId
            }
        });
    },
    addPermissionToRole(roleId,permissionId) {
        return request({
            url: '/permission/addPermissionToRole',
            method: 'get',
            params: {
                permissionId,
                roleId
            }
        });
    },
    deletePermission(id) {
        return request({
            url: '/permission/deletePermission',
            method: 'get',
            params: {
                id
            }
        });
    },
    updatePermission(permission) {
        return request({
            url: '/permission/updatePermission',
            method: 'post',
            data: permission
        });
    },
    login(username, password){
        return request({
            url: '/login',
            method: 'post',
            params: {
                username,
                password
            }
        });
    },
    logout(){
        return request({
            url: '/logout',
            method: 'post'
        });
    }
}
